package com.example.storage.controller;

import com.example.storage.service.StorageService;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class StorageController {

	private static final String SUCCESS = "SUCCESS";
	private static final String FAIL = "FAIL";

	private final StorageService storageService;

	public StorageController(StorageService storageService) {
		this.storageService = storageService;
	}

	@GetMapping(value = "/storage/{commodityCode}/{count}", produces = "application/json")
	public String storage(@PathVariable String commodityCode, @PathVariable int count) {
		int result = storageService.deduct(commodityCode, count);
		if (result == 1) {
			return SUCCESS;
		}
		return FAIL;
	}
}
